home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / term / pstricks.trm < prev    next >
Text File  |  1993-09-15  |  8KB  |  299 lines

  1. /*
  2.  * $Id: pstricks.trm%v 3.50 1993/07/09 05:35:24 woo Exp $
  3.  */
  4.  
  5. /* GNUPLOT - pstricks.trm */
  6. /*
  7.  * Copyright (C) 1990 - 1993
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted,
  11.  * provided that the above copyright notice appear in all copies and
  12.  * that both that copyright notice and this permission notice appear
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed
  17.  * as patches to released version.
  18.  *
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  *
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *   The PSTricks macros for LaTeX.
  25.  *
  26.  * AUTHORS
  27.  *   David Kotz
  28.  *
  29.  *   Raymond Toy    toy@soho.crd.ge.com
  30.  *    Modified the eepic.trm file to use PSTricks macros instead.
  31.  *
  32.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  33.  *
  34.  */
  35.  
  36. /*
  37.  *  This file contains the PSTricks terminal driver, intended for use with the
  38.  *  pstricks.sty macro package for LaTeX. This is an alternative to the
  39.  *  eepic and latex driver. You need pstricks.sty, and, of course, a printer
  40.  *  that understands PostScript.  Ghostscript understands Postscript too.
  41.  *
  42.  *  PSTricks is available via anonymous ftp from the /pub directory
  43.  *  at Princeton.EDU.  This driver comes definitely does not come close to
  44.  *  using the full capability of the PSTricks package.
  45.  */
  46.  
  47. #define PSTRICKS_PTS_PER_INCH (72.27)
  48. #define DOTS_PER_INCH (300)        /* resolution of printer we expect to use */
  49. #define PSTRICKS_UNIT (PSTRICKS_PTS_PER_INCH/DOTS_PER_INCH)    /* dot size in pt */
  50.  
  51. /* 5 inches wide by 3 inches high (default) */
  52. #define PSTRICKS_XMAX (5*DOTS_PER_INCH)    /* (PSTRICKS_PTS_PER_INCH/PSTRICKS_UNIT*5.0) */
  53. #define PSTRICKS_YMAX (3*DOTS_PER_INCH)    /* (PSTRICKS_PTS_PER_INCH/PSTRICKS_UNIT*3.0) */
  54.  
  55. #define PSTRICKS_HTIC (5*DOTS_PER_INCH/72)    /* (5./PSTRICKS_UNIT) */
  56. #define PSTRICKS_VTIC (5*DOTS_PER_INCH/72)    /* (5./PSTRICKS_UNIT) */
  57. #define PSTRICKS_HCHAR (DOTS_PER_INCH*53/10/72)    /* (5.3/PSTRICKS_UNIT) */
  58. #define PSTRICKS_VCHAR (DOTS_PER_INCH*11/72)    /* (11./PSTRICKS_UNIT) */
  59.  
  60. static unsigned int PSTRICKS_posx;
  61. static unsigned int PSTRICKS_posy;
  62. enum JUSTIFY    PSTRICKS_justify = LEFT;
  63. static int      PSTRICKS_angle = 0;
  64.  
  65. #define    PSTRICKS_TINY_DOT    0.25    /* A tiny dot, in points */
  66.  
  67. /* POINTS */
  68. #define PSTRICKS_POINT_TYPES 12        /* we supply more point types */
  69. static char  GPFAR * GPFAR PSTRICKS_points[] =
  70. {
  71.     "\\psset{dotstyle=square, dotangle=45}",
  72.     "\\psset{dotstyle=+}",
  73.     "\\psset{dotstyle=square}",
  74.     "\\psset{dotstyle=+, dotangle=45}",
  75.     "\\psset{dotstyle=triangle}",
  76.     "\\psset{dotstyle=pentagon}",
  77.     "\\psset{dotstyle=o}",
  78.     "\\psset{dotstyle=square*, dotangle=45}",
  79.     "\\psset{dotstyle=square*}",
  80.     "\\psset{dotstyle=triangle*}",
  81.     "\\psset{dotstyle=pentagon*}",
  82.     "\\psset{dotstyle=*}",
  83. };
  84.  
  85. /* LINES */
  86. #define PSTRICKS_NUMLINES 6        /* number of linetypes below */
  87. static char  GPFAR * GPFAR PSTRICKS_lines[] =
  88. {
  89.     "\\psset{linewidth=0.35pt,linestyle=solid}",        /* -2 border        */
  90.     "\\psset{linewidth=0.3pt,linestyle=dotted,dotsep=1pt}",    /* -1 axes, grid    */
  91.     "\\psset{linewidth=0.35pt,linestyle=solid}",        /*  0 solid thin    */
  92.     "\\psset{linewidth=0.35pt,linestyle=dashed,dash=5pt 3pt}",    /*  1 dashed        */
  93.     "\\psset{linewidth=0.35pt,linestyle=dotted,dotsep=3pt}",    /*  2 dotted        */
  94.     "\\psset{linewidth=0.35pt,linestyle=dashed,dash=10pt 3pt}"    /*  3 long dash    */
  95. };
  96.  
  97. static int      PSTRICKS_type;        /* current line type */
  98. static TBOOLEAN  PSTRICKS_inline = FALSE;/* are we in the middle of a line */
  99. static void     PSTRICKS_endline();    /* terminate any line in progress */
  100. static int      PSTRICKS_linecount = 0;    /* number of points in line so far */
  101.  
  102. #define PSTRICKS_LINEMAX 50        /* max value for linecount */
  103.  
  104. PSTRICKS_init()
  105. {
  106.     PSTRICKS_posx = PSTRICKS_posy = 0;
  107.     PSTRICKS_linetype(-1);
  108.     fprintf(outfile, "%% GNUPLOT: LaTeX picture using PSTRICKS macros\n");
  109.     fprintf(outfile, "\\psset{unit=%fpt}\n", PSTRICKS_UNIT);
  110.     fprintf(outfile, "\\psset{arrowsize=3pt 3.2 1.4 .3}\n");
  111. }
  112.  
  113.  
  114. PSTRICKS_scale(xs, ys)
  115.     double          xs, ys;        /* scaling factors */
  116. {
  117.     register struct termentry *t = &term_tbl[term];
  118.  
  119.     /* we change the table for use in graphics.c and PSTRICKS_graphics */
  120.     t->xmax = (unsigned int) (PSTRICKS_XMAX * xs);
  121.     t->ymax = (unsigned int) (PSTRICKS_YMAX * ys);
  122.  
  123.     return (TRUE);
  124. }
  125.  
  126. PSTRICKS_graphics()
  127. {
  128.     register struct termentry *t = &term_tbl[term];
  129.  
  130.     fprintf(outfile, "\\begin{pspicture}(0,0)(%d,%d)\n", t->xmax, t->ymax);
  131.     fprintf(outfile, "\\tenrm\n");
  132. }
  133.  
  134.  
  135. PSTRICKS_text()
  136. {
  137.     PSTRICKS_endline();
  138.     fprintf(outfile, "\\end{pspicture}\n");
  139. }
  140.  
  141.  
  142. PSTRICKS_linetype(linetype)
  143.     int             linetype;
  144. {
  145.     PSTRICKS_endline();
  146.  
  147.     if (linetype >= PSTRICKS_NUMLINES - 2)
  148.     linetype %= (PSTRICKS_NUMLINES - 2);
  149.  
  150.     PSTRICKS_type = linetype;
  151. }
  152.  
  153.  
  154.  
  155. PSTRICKS_move(x, y)
  156.     unsigned int    x, y;
  157. {
  158.     PSTRICKS_endline();
  159.  
  160.     PSTRICKS_posx = x;
  161.     PSTRICKS_posy = y;
  162. }
  163.  
  164.  
  165. PSTRICKS_point(x, y, number)        /* version of line_and_point */
  166.     unsigned int    x, y;
  167.     int             number;        /* type of point */
  168. {
  169.     PSTRICKS_move(x, y);
  170.  
  171.     /* Print the character defined by 'number'; number < 0 means
  172.       to use a dot, otherwise one of the defined points. */
  173.  
  174.     if (number < 0) {
  175.     fprintf(outfile, "\\qdisk(%d,%d){%fpt}\n",
  176.         x, y, PSTRICKS_TINY_DOT);
  177.     } else {
  178.     fprintf(outfile, "%s\\psdots(%d,%d)\n",
  179.         PSTRICKS_points[number % PSTRICKS_POINT_TYPES],
  180.         x, y);
  181.     }
  182. }
  183.  
  184.  
  185. PSTRICKS_vector(ux, uy)
  186.     unsigned int    ux, uy;
  187. {
  188.     if (!PSTRICKS_inline) {
  189.     PSTRICKS_inline = TRUE;
  190.  
  191.     /* Start a new line. This depends on line type */
  192.     fprintf(outfile, "%s\\psline(%u,%u)",
  193.         PSTRICKS_lines[PSTRICKS_type + 2],
  194.         PSTRICKS_posx, PSTRICKS_posy);
  195.     PSTRICKS_linecount = 1;
  196.     } else {
  197.     /*
  198.      * Even though we are in middle of a path,
  199.      * we may want to start a new path command.
  200.      * If they are too long then latex will choke.
  201.      */
  202.     if (PSTRICKS_linecount++ >= PSTRICKS_LINEMAX) {
  203.         fprintf(outfile, "\n");
  204.         fprintf(outfile, "%s\\psline(%u,%u)",
  205.             PSTRICKS_lines[PSTRICKS_type + 2],
  206.             PSTRICKS_posx, PSTRICKS_posy);
  207.         PSTRICKS_linecount = 1;
  208.     }
  209.     }
  210.     fprintf(outfile, "(%u,%u)", ux, uy);
  211.     PSTRICKS_posx = ux;
  212.     PSTRICKS_posy = uy;
  213. }
  214.  
  215. static void
  216. PSTRICKS_endline()
  217. {
  218.     if (PSTRICKS_inline) {
  219.     fprintf(outfile, "\n");
  220.     PSTRICKS_inline = FALSE;
  221.     }
  222. }
  223.  
  224.  
  225. PSTRICKS_arrow(sx, sy, ex, ey, head)
  226.     int             sx, sy, ex, ey;
  227.     TBOOLEAN         head;
  228. {
  229.     fprintf(outfile, "\\psline[linestyle=solid]%s(%d,%d)(%d,%d)\n",
  230.         head ? "{->}" : "",
  231.         sx, sy, ex, ey);
  232.  
  233.     PSTRICKS_posx = ex;
  234.     PSTRICKS_posy = ey;
  235. }
  236.  
  237.  
  238. PSTRICKS_put_text(x, y, str)
  239.     int             x, y;        /* reference point of string */
  240.     char            str[];        /* the text */
  241. {
  242.     PSTRICKS_endline();
  243.  
  244.     fprintf(outfile, "\\rput");
  245.  
  246.     /* Set justification */
  247.  
  248.     switch (PSTRICKS_justify) {
  249.     case LEFT:
  250.     fprintf(outfile, "[l]");
  251.     break;
  252.     case CENTRE:
  253.     break;
  254.     case RIGHT:
  255.     fprintf(outfile, "[r]");
  256.     break;
  257.     }
  258.  
  259.     /* Set text angle */
  260.  
  261.     switch (PSTRICKS_angle) {
  262.     case 0:
  263.     break;
  264.     case 1:
  265.     fprintf(outfile, "{L}");
  266.     break;
  267.     }
  268.  
  269.     /* Set reference position and text */
  270.  
  271.     fprintf(outfile, "(%d,%d){%s}\n", x, y, str);
  272.  
  273. }
  274.  
  275.  
  276.  
  277. int 
  278. PSTRICKS_justify_text(mode)
  279.     enum JUSTIFY    mode;
  280. {
  281.     PSTRICKS_justify = mode;
  282.     return (TRUE);
  283. }
  284.  
  285. int 
  286. PSTRICKS_text_angle(angle)
  287.     int             angle;
  288. {
  289.     PSTRICKS_angle = angle;
  290.     return (TRUE);
  291. }
  292.  
  293. PSTRICKS_reset()
  294. {
  295.     PSTRICKS_endline();
  296.     PSTRICKS_posx = PSTRICKS_posy = 0;
  297. }
  298.  
  299.